<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的博客首页</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }

        /* 导航栏样式 */
        nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #333;
            color: white;
            padding: 1rem 2rem;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .logo {
            font-size: 1.5rem;
            font-weight: bold;
        }

        .nav-links {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }

        .nav-links li {
            margin-left: 1.5rem;
        }

        .nav-links a {
            color: white;
            text-decoration: none;
            transition: color 0.3s ease;
        }

        .nav-links a:hover {
            color: #ffc107;
        }

        .burger {
            display: none;
            cursor: pointer;
        }

        .burger div {
            width: 25px;
            height: 3px;
            background-color: white;
            margin: 5px;
            transition: all 0.3s ease;
        }

        /* 用户头像样式 */
        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-image: url('avatar.png'); /* 替换为实际的头像图片路径 */
            background-size: cover;
            cursor: pointer;
        }

        /* 英雄区域样式 */
        .hero {
            background-image: url('background.png'); /* 设置背景图片 */
            background-size: cover;
            background-position: center;
            height: 500px;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            color: white;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
        }

        .hero-content {
            max-width: 600px;
        }

        .hero h1 {
            font-size: 3rem;
            margin-bottom: 1rem;
        }

        .hero p {
            font-size: 1.2rem;
            margin-bottom: 2rem;
        }

        .cta-button {
            background-color: #ffc107;
            color: white;
            padding: 0.8rem 2rem;
            text-decoration: none;
            border-radius: 5px;
            font-weight: bold;
            transition: background-color 0.3s ease;
        }

        .cta-button:hover {
            background-color: #e0a800;
        }

        /* 文章列表样式 */
        .article-list {
            padding: 2rem;
        }

        .article-container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 2rem;
        }

        .article {
            background-color: white;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .article img {
            width: 100%;
            height: auto;
        }

        .article-info {
            padding: 1rem;
        }

        .article h2 {
            font-size: 1.5rem;
            margin-bottom: 0.5rem;
        }

        .article-meta {
            font-size: 0.9rem;
            color: #777;
            margin-bottom: 1rem;
        }

        .article-excerpt {
            margin-bottom: 1rem;
        }

        .read-more {
            color: #007bff;
            text-decoration: none;
            font-weight: bold;
        }

        .read-more:hover {
            text-decoration: underline;
        }

        /* 页脚样式 */
        footer {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 1rem;
        }

        /* 响应式设计 */
        @media screen and (max-width: 768px) {
            .nav-links {
                position: absolute;
                right: 0px;
                height: 92vh;
                top: 8vh;
                background-color: #333;
                display: flex;
                flex-direction: column;
                align-items: center;
                width: 50%;
                transform: translateX(100%);
                transition: transform 0.5s ease-in;
            }

            .nav-links li {
                opacity: 0;
            }

            .burger {
                display: block;
            }

            .nav-active {
                transform: translateX(0%);
            }
        }

        @keyframes navLinkFade {
            from {
                opacity: 0;
                transform: translateX(50px);
            }
            to {
                opacity: 1;
                transform: translateX(0px);
            }
        }

        .toggle .line1 {
            transform: rotate(-45deg) translate(-5px, 6px);
        }

        .toggle .line2 {
            opacity: 0;
        }

        .toggle .line3 {
            transform: rotate(45deg) translate(-5px, -6px);
        }
    </style>
</head>

<body>
    <!-- 导航栏 -->
    <nav>
        <div class="logo">我的博客</div>
        <ul class="nav-links">
            <li><a href="#">首页</a></li>
            <li><a href="#">文章分类</a></li>
        </ul>
        <div class="user-avatar"></div>
        <div class="burger">
            <div class="line1"></div>
            <div class="line2"></div>
            <div class="line3"></div>
        </div>
    </nav>

    <!-- 英雄区域 -->
    <section class="hero">
        <div class="hero-content">
            <h1>探索知识的海洋</h1>
            <p>在这里，你可以发现各种有趣的文章和见解</p>
            <a href="#" class="cta-button">开始阅读</a>
        </div>
    </section>

    <!-- 文章列表 -->
    <section class="article-list">
        <div class="article-container" id="article-container">
            <!-- 文章将通过 JavaScript 动态插入到这里 -->
        </div>
    </section>

    <!-- 页脚 -->
    <footer>
        <p>&copy; 2024 我的博客. 保留所有权利.</p>
    </footer>

    <script>
        // 导航栏响应式菜单
        const navSlide = () => {
            const burger = document.querySelector('.burger');
            const nav = document.querySelector('.nav-links');
            const navLinks = document.querySelectorAll('.nav-links li');

            burger.addEventListener('click', () => {
                // 切换导航栏显示状态
                nav.classList.toggle('nav-active');

                // 动画效果
                navLinks.forEach((link, index) => {
                    if (link.style.animation) {
                        link.style.animation = '';
                    } else {
                        link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
                    }
                });

                // 汉堡菜单动画
                burger.classList.toggle('toggle');
            });
        };

        navSlide();

        // 用户头像点击事件
        const userAvatar = document.querySelector('.user-avatar');
        userAvatar.addEventListener('click', () => {
            alert('查询用户信息'); // 这里可以替换为实际的查询用户信息的逻辑
        });

        // 从后台获取文章数据并渲染
        async function fetchArticles() {
            try {
                const response = await fetch('/api/posts'); // 替换为实际的 API 地址
                const posts = await response.json();

                const articleContainer = document.getElementById('article-container');
                articleContainer.innerHTML = ''; // 清空现有内容

                posts.forEach(post => {
                    const article = document.createElement('article');
                    article.classList.add('article');

                    const img = document.createElement('img');
                    img.src = post.image;
                    img.alt = '文章配图';

                    const articleInfo = document.createElement('div');
                    articleInfo.classList.add('article-info');

                    const title = document.createElement('h2');
                    title.textContent = post.title;

                    const meta = document.createElement('p');
                    meta.classList.add('article-meta');
                    meta.textContent = `作者: ${post.author} | 发布时间: ${post.date}`;

                    const excerpt = document.createElement('p');
                    excerpt.classList.add('article-excerpt');
                    excerpt.textContent = post.excerpt;

                    const readMore = document.createElement('a');
                    readMore.href = '#';
                    readMore.classList.add('read-more');
                    readMore.textContent = '阅读更多';

                    articleInfo.appendChild(title);
                    articleInfo.appendChild(meta);
                    articleInfo.appendChild(excerpt);
                    articleInfo.appendChild(readMore);

                    article.appendChild(img);
                    article.appendChild(articleInfo);

                    articleContainer.appendChild(article);
                });
            } catch (error) {
                console.error('获取文章数据失败:', error);
            }
        }

        // 页面加载时获取文章数据
        fetchArticles();
    </script>
</body>

</html>